package com.xiaomei.manager.web.controller;

import java.sql.Timestamp;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.xiaomei.manager.model.Authinfo;
import com.xiaomei.manager.model.Enchashment;
import com.xiaomei.manager.model.Order;
import com.xiaomei.manager.service.IEnchashmentService;
import com.xiaomei.manager.web.dto.req.EnchashmentQueryDto;
import com.xiaomei.manager.web.page.Page;

@Controller
@RequestMapping(value="/withdraw")
public class WithdrawController {
	@Autowired
	private IEnchashmentService iEnchashmentService;
	
	@RequiresPermissions("withdraw:view")
	@RequestMapping(method = RequestMethod.GET)
	public String list(HttpServletRequest request,EnchashmentQueryDto dto, Page<Enchashment> page){
		iEnchashmentService.getEnchashmentList(dto, page);
		request.setAttribute("dto", dto);
		request.setAttribute("page", page);
		return "/withdraw/list";
	}
	@RequiresPermissions("withdraw:update")
	@RequestMapping(value = "/{id}/update",method = RequestMethod.GET)
	public String detail(@PathVariable("id") int id, Model model){
		Enchashment selectByPrimaryKey = (Enchashment)iEnchashmentService.selectByPrimaryKey(id);
		model.addAttribute("Enchashment",selectByPrimaryKey);	
		return "/withdraw/detail";
	}
	@RequiresPermissions("withdraw:update")
	@RequestMapping(value = "/{id}/update",method = RequestMethod.POST)
	public String update(Enchashment enchashment, RedirectAttributes redirectAttributes){
		enchashment.setRecordTime(new Timestamp(System.currentTimeMillis()));
		iEnchashmentService.updateByPrimaryKeySelective(enchashment);
		redirectAttributes.addFlashAttribute("msg", "修改成功");
		return "redirect:/withdraw";
	}
}
